#include"SystemHead.h"

#define FIFO "MyFIFO"
#define FIFO2 "MyFIFO2"

int main()
{
    mkfifo(FIFO,S_IRUSR|S_IWUSR);
    mkfifo(FIFO2,S_IRUSR|S_IWUSR);

    int FIFOfd=open(FIFO,O_WRONLY);
    if(FIFOfd==-1)
    {
        perror("open:");
        exit(-2);
    }

    int FIFOfd2=open(FIFO2,O_RDONLY);
    if(FIFOfd2==-1)
    {
        perror("open:");
        exit(-2);
    }
    while(1)
    {
        char buff[1024]={0};
        
        printf("parent input message to client :");

        memset(buff,0,sizeof(buff));
        
        scanf("%[^\n]",buff);
        getchar();
        write(FIFOfd,buff,sizeof(buff));
        if(strcmp(buff,"exit")==0)
        {
            break;
        }
        read(FIFOfd2,buff,sizeof(buff));
        if(strcmp(buff,"exit")==0)
        {
            break;
        }
        printf("client said to client2 : %s\n",buff);
    }

    close(FIFOfd);
    close(FIFOfd2);

    char temp[100]={0};
    sprintf(temp,"rm -f %s",FIFO);
    system(temp);
    memset(temp,0,100);
    sprintf(temp,"rm -f %s",FIFO2);
    system(temp);
}